
import LanguageMngTs from "../Managers/LanguageMngTs";
import RoomTypes from "../Static/RoomTypes";
import RoomConfig from "../Static/RoomConfig";

cc.Class({
    extends: cc.Component,

    properties: {

    },

    ctor(){
        this.BackToLobbyOpt = {
            CONFIRM:1,
            CANCEL:2,
            DIRECTORY:3,
        }

        this.FLOWER = {
            BLACK:1,
            HEART:2,
            FLOWER:3,
            DIAMOND:4,
            JOKER:5,
        }

        this.SeperateType = {
            NONE:0,
            INVALID:1,
            SET:2,
            // PURE_SEQUENCE:3,
            SEQUENCE:4,
            ALL_MIX:5
        }

        this.OptionState = {
            DISPATCHING:1,  //发牌阶段
            WAIT:2,     //对方行动阶段
            GRAB:3,     //用户抓牌阶段
            PLAY:4,     //用户打牌阶段
            GROUP:5,    //用户组牌阶段
            CALCULATING:6   //结算阶段
        }

        this.LanguageType = {
            CHINESE:1,
            ENGLISH:2
        }

        this.SETTING = {
            ON:1,
            OFF:2,
        }

        this.RoomType = {
            POINTS:1,
            POOL:2,
            // PRACTISE:0,
            DEAL:3
        }

        this.RoomMode = {//1-轮数，2=人数，3=mode
            POOL_101:0x100,
            POOL_201:0x200,
            //用来计算人数的掩码，将轮数和mode都掩掉
            BASE_VALUE_2:0X020,
            BASE_VALUE_6:0X060,

            ROUND_VALUE_NONE:0X000,
            ROUND_VALUE_3:0X300,
            ROUND_VALUE_6:0X600,

            PRACTICE:0x000,
            BEGINNER:0x001,
            ROOKIES:0x002,
            STARS:0x003,
            AMAZING:0x004,
        }

        this.RoomNetState = {

            //状态 0=未准备 1=游戏中 2=结算中 3=下一轮准备中 4=洗牌中 5=下一轮倒计时
            // state = 0;
            IDLE:0, //READY TO START
            PLAYING:1,  //cd before start
            IN_GAME:2,  //in game
            COMMITTING:3, //commit
            BEFORE_NEXT_ROUND:4,  //cd before next round
            COUNTTING:5,    //shuffling
            INTERVAL:6, //CD BEFORE NEXT BATTLE
        }

        //copy from server
        this.MSG_TYPE = { HEART_BEAT: 1, CREATE: 2, DESTROY: 3, MODIFY: 4, TRIGGER: 5 };

        this.ReadyState = {
            NOTREADY:0,
            READY:1,
            GAMEING:2,
            COMMITED:3,
            DROPED:4,
            ELIMINATED:5
        }

        this.GrabFrom = {
            DISCARDS:1,
            DECK:2
        }

        this.Languages = {
            ENGLISH:1,
            HINDI:2,
            TALUGU:3,
            TAIMIL:4,
            GULILATTER:5,
            MALATY:6
        }
    },

    reversePointRooms:function () {
        this.reversePoint = !this.reversePoint
        this.point.reverse()
    },

    reversePoolRooms:function () {
        this.reversePool = !this.reversePool
        this.pool.reverse()
    },

    reverseDealRooms:function () {
        this.reverseDeal = !this.reverseDeal
        this.deal.reverse()
    },

    getNameByRoomType:function (type) {
        if(type === RoomTypes.POINTS){
            return "Point"
        }else if(type === RoomTypes.POOL){
            return "Pool"
        }else if(type === RoomTypes.DEAL){
            return "Deal"
        }else {
            return "Unknown"
        }
    },

    getRoomObj:function (type, roomId) {
        let array = null
        if(type === cc.gg.enumConfig.RoomType.POINTS){
            array = RoomConfig.point
        }else if(type === cc.gg.enumConfig.RoomType.POOL){
            array = RoomConfig.pool
        }else if(type === cc.gg.enumConfig.RoomType.DEAL){
            array = RoomConfig.deal
        }
        for(let i=0;i<array.length;i++){
            let obj = array[i]
            if(roomId === obj.id){
                return obj
            }
        }
        return null
    },

    getRoomObjs:function (type, player, round) {
        let array = null
        let isPool = false
        if(type === cc.gg.enumConfig.RoomType.POINTS){
            array = RoomConfig.point
        }else if(type === cc.gg.enumConfig.RoomType.POOL){
            array = RoomConfig.pool
        }else if(type === cc.gg.enumConfig.RoomType.DEAL){
            array = RoomConfig.deal
        }

        let resultArray = []
        for(let i=0;i<array.length;i++){
            let obj = array[i]
            // let tmpP = obj.id & 0x0f0
            // let tmpL = obj.id & 0x00f
            // player=2  真金场    player=6  练习场
            if(player === 2){
                if(obj.e_fee <= 0) continue;
                if(round){
                    if(round === obj.r_top){
                        resultArray.push(obj)
                    }else {
                        continue
                    }
                }else
                    resultArray.push(obj)
            }else{
                if(obj.e_fee <= 0){
                    resultArray.push(obj)
                }
            }
        }
        resultArray.sort((a , b)=>{
            return a.e_fee - b.e_fee;
        })
        return resultArray
    },

    getRoomInfoById:function (type,id) {
        let array = null
        if(type === cc.gg.enumConfig.RoomType.POINTS){
            array = RoomConfig.point
        }else if(type === cc.gg.enumConfig.RoomType.POOL){
            array = RoomConfig.pool
        }else if(type === cc.gg.enumConfig.RoomType.DEAL){
            array = RoomConfig.deal
        }

        for(let i=0;i<array.length;i++){
            let obj = array[i]
            if(obj.id === id)
                return obj
        }
        return null
    }

});
